﻿using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Linq;
using System.Text;
using System.Windows.Forms;
using System.Drawing.Imaging;
using Microsoft.Xna.Framework.Graphics;
using Microsoft.Xna.Framework.Content;
using System.IO;

namespace MapEditor
{
    public partial class frmTools : Form
    {

        public enum DrawType { Objects = 1, SingleWall = 2, RectWall = 3, EditMode = 4, None = 5 }


        private DrawType m_dt;

        private frmEditor fE;

        public frmTools()
        {
            InitializeComponent();
        }

        public frmTools(ref frmEditor ed)
        {
            InitializeComponent();
            this.fE = ed;
        }

        public DrawType DrawingType
        {
            get
            {
                return m_dt;
            }
            set
            {
                m_dt = value;
            }
        }

        public void SetDrawingType(DrawType dt)
        {
            switch (m_dt)
            {
                case DrawType.Objects:
                    panPen_Click(new object(), new EventArgs());
                    break;
                case DrawType.RectWall:
                    panRect_Click(new object(), new EventArgs());
                    break;
                case DrawType.SingleWall:
                    panLine_Click(new object(), new EventArgs());
                    break;
                case DrawType.EditMode:
                    panEdit_Click(new object(), new EventArgs());
                    break;
                case DrawType.None:
                    ResetBorderStyles();
                    break;
            }
        }

        private void frmTools_Load(object sender, EventArgs e)
        {
            // Init images and borderstyles

            panEdit.BackgroundImage = Image.FromFile("C:\\Users\\Usager\\Documents\\Visual Studio 2010\\Projects\\MAP\\MapEditor\\MapEditorContent\\Icons\\arrow.png");
            panEdit.BackgroundImageLayout = ImageLayout.Stretch;
            panEdit.BorderStyle = BorderStyle.None;
            panErease.BackgroundImage = Image.FromFile("C:\\Users\\Usager\\Documents\\Visual Studio 2010\\Projects\\MAP\\MapEditor\\MapEditorContent\\Icons\\ereaser.png");
            panErease.BackgroundImageLayout = ImageLayout.Stretch;
            panErease.BorderStyle = BorderStyle.None;
            panPen.BackgroundImage = Image.FromFile("C:\\Users\\Usager\\Documents\\Visual Studio 2010\\Projects\\MAP\\MapEditor\\MapEditorContent\\Icons\\pen.png");
            panPen.BackgroundImageLayout = ImageLayout.Stretch;
            panPen.BorderStyle = BorderStyle.Fixed3D;
            panLine.BackgroundImage = Image.FromFile("C:\\Users\\Usager\\Documents\\Visual Studio 2010\\Projects\\MAP\\MapEditor\\MapEditorContent\\Icons\\line.png");
            panLine.BackgroundImageLayout = ImageLayout.Stretch;
            panLine.BorderStyle = BorderStyle.None;
            panRect.BackgroundImage = Image.FromFile("C:\\Users\\Usager\\Documents\\Visual Studio 2010\\Projects\\MAP\\MapEditor\\MapEditorContent\\Icons\\rectangle.png");
            panRect.BackgroundImageLayout = ImageLayout.Stretch;
            panRect.BorderStyle = BorderStyle.None;

        }

        private void panEdit_Click(object sender, EventArgs e)
        {
            if (panEdit.BorderStyle == BorderStyle.None)
            {
                ResetBorderStyles();
                panEdit.BorderStyle = BorderStyle.Fixed3D;
                DrawingType = DrawType.EditMode;
            }
            else
            {
                panEdit.BorderStyle = BorderStyle.None;
                DrawingType = DrawType.None;
            }
        }

        private void panPen_Click(object sender, EventArgs e)
        {
            if (panPen.BorderStyle == BorderStyle.None)
            {
                ResetBorderStyles();
                panPen.BorderStyle = BorderStyle.Fixed3D;
                DrawingType = DrawType.Objects;
            }
            else
            {
                panPen.BorderStyle = BorderStyle.None;
                DrawingType = DrawType.None;
            }
        }

        private void panErease_Click(object sender, EventArgs e)
        {
            if (panErease.BorderStyle == BorderStyle.None)
            {
                ResetBorderStyles();
                panErease.BorderStyle = BorderStyle.Fixed3D;
                DrawingType = DrawType.Objects;
            }
            else
            {
                panErease.BorderStyle = BorderStyle.None;
                DrawingType = DrawType.None;
            }
        }

        private void panLine_Click(object sender, EventArgs e)
        {
            if (panLine.BorderStyle == BorderStyle.None)
            {
                ResetBorderStyles();
                panLine.BorderStyle = BorderStyle.Fixed3D;
                DrawingType = DrawType.SingleWall;
            }
            else
            {
                panLine.BorderStyle = BorderStyle.None;
                DrawingType = DrawType.None;
            }
        }

        private void panRect_Click(object sender, EventArgs e)
        {
            if (panRect.BorderStyle == BorderStyle.None)
            {
                ResetBorderStyles();
                panRect.BorderStyle = BorderStyle.Fixed3D;
                DrawingType = DrawType.RectWall;
            }
            else
            {
                panRect.BorderStyle = BorderStyle.None;
                DrawingType = DrawType.None;
            }
        }

        private void ResetBorderStyles()
        {
            panEdit.BorderStyle = BorderStyle.None;
            panErease.BorderStyle = BorderStyle.None;
            panLine.BorderStyle = BorderStyle.None;
            panRect.BorderStyle = BorderStyle.None;
            panPen.BorderStyle = BorderStyle.None;
        }

        public bool IsEreasing()
        {
            if (panErease.BorderStyle == BorderStyle.None)
                return false;
            else
                return true;
        }

    }
}
